
#ifndef __BUTTON__H
#define __BUTTON__H

#include "type.h"

#define BUTTON_PRESS				1
#define BUTTON_RELEASE				0

typedef struct __BUTTON_STRUCT__ BUTTON_STRUCT;
struct __BUTTON_STRUCT__{
	uint8_t jitter_tick;
	uint8_t long_press_tick;
	uint8_t long_press_repeat_tick;
	uint8_t press_tick_count;
	uint8_t last_state;
	uint8_t (*hal_read_button_state_callbakc)(BUTTON_STRUCT* button);
	void (*press_callback)(BUTTON_STRUCT* button);
	void (*release_callback)(BUTTON_STRUCT* button);
	void (*long_press_callback)(BUTTON_STRUCT* button);
};

void button_scan_tick_handler(BUTTON_STRUCT* button, uint8_t tick);

typedef struct
{
	uint8_t button_num;
	uint8_t button_pointer;
	BUTTON_STRUCT* button;
} BUTTON_GROUP_STRUCT;

void button_group_scan_tick_handler(BUTTON_GROUP_STRUCT* button_group, uint16_t ticks);
void button_group_init(BUTTON_GROUP_STRUCT* button_group,
						uint8_t button_group_button_num,
						BUTTON_STRUCT* button_space);
BUTTON_STRUCT* button_new(BUTTON_GROUP_STRUCT* button_group,
							uint8_t jitter_tick,
							uint8_t long_press_tick,
							uint8_t long_press_repeat_tick,
							uint8_t (*hal_read_button_state_callbakc_handler)(BUTTON_STRUCT* button),
							void (*press_callback_handler)(BUTTON_STRUCT* button),
							void (*release_callback_handler)(BUTTON_STRUCT* button),
							void (*long_press_callback_handler)(BUTTON_STRUCT* button));

#endif //
